import { reg } from 'services/home';
import router from 'umi/router';
export default {
  namespace: 'home',
  state: {
    list: {
      productList: '',
      bannerList: [
        {
          isShow: 1,
          url: null,
          imageUrl:
            'https://edu-image.nosdn.127.net/f37df0f915d14cf2930a29d555f22dc4.png?imageView&quality=100',
          comment: '仅做展示',
        },
        {
          isShow: 1,
          url: null,
          imageUrl:
            'https://edu-image.nosdn.127.net/e00ae81bb86e482c965949205775d695.png?imageView&quality=100',
          comment: '仅做展示',
        },
        {
          isShow: 1,
          url: null,
          imageUrl:
            'https://edu-image.nosdn.127.net/990af11b2d734bb0b24b74da531dad12.png?imageView&quality=100',
          comment: '仅做展示',
        },
      ],
    },
  },
  effects: {
    *reg({ payload, callback }, { call, put }) {
      const response = yield call(reg, payload);
      yield put({
        type: 'setData',
        payload: response.data,
      });
    },
  },
  reducers: {
    setData(state, { payload }) {
      return {
        ...state,
        list: payload,
      };
    },
  },
  subscriptions: {
    setup({ dispatch, history }) {
      return history.listen(({ pathname, search }) => {
        // if (pathname == '/home' || pathname == '/') {
        //   dispatch({
        //     type: 'reg',
        //   });
        // }
      });
    },
  },
};
